﻿using B.S.Backtrack.Infrastructure.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.S.Backtrack.Infrastructure.Implement
{
    public class BaseRepository<T>:IBaseRepository<T> where T : class
    {
        private readonly BTDBContext db;

        public BaseRepository(BTDBContext db)
        {
            this.db = db;
        }

        public int Add(T entity)
        {
            db.Set<T>().Add(entity);
            return db.SaveChanges();
        }

        public int AddRange(List<T> entities)
        {
            db.Set<T>().AddRange(entities);
            return db.SaveChanges();
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        public int Update(T entity)
        {
            db.Set<T>().Update(entity);
            return db.SaveChanges();
        }

        public int UpdateRange(List<T> entities)
        {
            db.Set<T>().UpdateRange(entities);
            return db.SaveChanges();
        }
    }
}
